using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class DataListPagingPage : System.Web.UI.Page
{
    int pageSize = 9;
    ControlProviders controlProviders;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            lblPage.Text="1";
            txtPage.Text="1";
            controlProviders = new ControlProviders();
            int rows= controlProviders.FillRecruiterAccount(this.DataList1, 
            pageSize);
            lblPages.Text = (rows/pageSize + ((rows%pageSize)>0?1:0)).ToString();
            rvPage.MaximumValue=  lblPages.Text;
            linkPrevious.Enabled = false;
            linkFirst.Enabled = false;
        }
    }
    
     
    protected void linkFirst_Click(object sender, EventArgs e)
    {
        controlProviders = new ControlProviders();
        controlProviders.FillRecruiterAccount(this.DataList1, 0, pageSize);
        lblPage.Text = "1" ;
        txtPage.Text = "1";
        linkPrevious.Enabled = false;
        linkFirst.Enabled = false;
        linkNext.Enabled = true;
        linkLast.Enabled = true;
    }
    protected void linkPrevious_Click(object sender, EventArgs e)
    {
        linkNext.Enabled = true;
        linkLast.Enabled = true;
        int currentPage=Convert.ToInt32(lblPage.Text);
        if(currentPage>1) currentPage--;
        controlProviders = new ControlProviders();
            controlProviders.FillRecruiterAccount(this.DataList1, 
        (currentPage - 1) * pageSize  , pageSize);
        lblPage.Text = currentPage.ToString();
        txtPage.Text = lblPage.Text;
        if (currentPage == 1)
           {
            linkPrevious.Enabled = false;
            linkFirst.Enabled=false;
            }
        else
        {
            linkFirst.Enabled = true;
            linkPrevious.Enabled = true;
            }
    }
   
    protected void linkNext_Click(object sender, EventArgs e)
    {
        linkFirst.Enabled = true;
        linkPrevious.Enabled = true;
        int currentPage = Convert.ToInt32(lblPage.Text);
        if (currentPage > 0) currentPage++;
        controlProviders = new ControlProviders();
            controlProviders.FillRecruiterAccount(this.DataList1, 
        (currentPage - 1) * pageSize  , pageSize);
        lblPage.Text = currentPage.ToString();
        txtPage.Text = lblPage.Text;
        if (currentPage == Convert.ToInt32(lblPages.Text))
        {
            linkLast.Enabled = false;
            linkNext.Enabled = false;
            }
        else
        {
            linkLast.Enabled = true;
            linkNext.Enabled = true;
            }
    }
    
   
    protected void linkLast_Click(object sender, EventArgs e)
    {
        linkNext.Enabled = false;
        linkLast.Enabled = false;
        linkFirst.Enabled = true;
        linkPrevious.Enabled = true;     
        controlProviders = new ControlProviders();
        controlProviders.FillRecruiterAccount(this.DataList1, (Convert.ToInt32(lblPages.Text) - 1) * pageSize  , pageSize);
        lblPage.Text = lblPages.Text;
        txtPage.Text = lblPage.Text;
    }
    protected void btnGo_Click(object sender, EventArgs e)
    {       
        int currentPage = Convert.ToInt32(txtPage.Text);
        
        controlProviders = new ControlProviders();
        controlProviders.FillRecruiterAccount(this.DataList1,
        (currentPage-1)* pageSize  , pageSize);
        lblPage.Text = currentPage.ToString();
        linkFirst.Enabled = true;
        linkPrevious.Enabled = true;
        linkLast.Enabled = true;
        linkNext.Enabled = true;
        if (currentPage == Convert.ToInt32(lblPages.Text))
        {
            linkLast.Enabled = false;
            linkNext.Enabled = false;
            
        }
        if (currentPage == 1)
        {
            
            linkFirst.Enabled = false;
            linkPrevious.Enabled = false;
        }
    }
}
